package com.vm.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TabHost;
import com.vm.activity.SearchActivity;
import com.wwt.app.R;

public class TopFragment extends BaseFragment {

	Button rbtn_month_ranking;
	Button rbtn_week_ranking;
	Button rbtn_day_ranking;
	TabHost tabHost;
	Button btn_search;
	ImageButton imgbtn_back;
	private View view;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		Log.i("CategoryFragment", "onCreateView");

		if (view == null) {
			view = inflater.inflate(R.layout.ranking, null);
		} else {
			// 缓存的rootView需要判断是否已经被加过parent
			// 如果有parent需要从parent删除
			ViewGroup parent = (ViewGroup) view.getParent();
			if (parent != null) {
				parent.removeView(view);
			}
		}
		return view;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

		// tabHost = getTabHost();
		// int count = TabConst.ConValue.HotTabText.length;
		// for (int i = 0; i < count; i++) {
		// TabSpec tabspec = tabHost
		// .newTabSpec(
		// getResources().getString(ConValue.HotTabText[i]))
		// .setIndicator(
		// getResources().getString(ConValue.HotTabText[i]))
		// .setContent(getTabItemIntent(i));
		// tabHost.addTab(tabspec);
		// }
		// tabHost.setCurrentTab(0);
		init();

	}

	public void init() {
		rbtn_month_ranking = (Button) view
				.findViewById(R.id.rbtn_month_ranking);
		rbtn_week_ranking = (Button) view.findViewById(R.id.rbtn_week_ranking);
		rbtn_day_ranking = (Button) view.findViewById(R.id.rbtn_day_ranking);
		btn_search = (Button) view.findViewById(R.id.btn_search);
		imgbtn_back = (ImageButton) view.findViewById(R.id.imgbtn_back);
		rbtn_month_ranking.setOnClickListener(btn_listener);
		rbtn_week_ranking.setOnClickListener(btn_listener);
		rbtn_day_ranking.setOnClickListener(btn_listener);
		btn_search.setOnClickListener(searchClickListener);
		imgbtn_back.setOnClickListener(btn_listener);

	}

	public OnClickListener btn_listener = new OnClickListener() {

		public void onClick(View v) {
			if (v == rbtn_day_ranking) {
				tabHost.setCurrentTab(0);
			}
			if (v == rbtn_week_ranking) {
				tabHost.setCurrentTab(1);
			} else if (v == rbtn_month_ranking) {
				tabHost.setCurrentTab(2);
			} else if (v == imgbtn_back) {
				getActivity().onBackPressed();
			}
		}

	};

	public OnClickListener searchClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			Intent intent = new Intent(getActivity(), SearchActivity.class);
			startActivity(intent);
		}
	};

	@Override
	protected void lazyLoad() {
		// TODO Auto-generated method stub

	}

}
